/********************** 
作者：邬畏畏
时间：2013-10-20
---------------
生成的Div：
<div id="content" style="overflow:hidden"> 页面
	<div id="wInnerContent">
		innerHTML,通过wHScrollPage.addPage()添加到此处
	</div>
	<div id="wPage">左下角的方块</div>
</div> 页面
属性说明：
parentStr:是容器ID字符串，如"#content"
parent:页面容器DOM对象
pageCount:有多少页
nr:页的内容
page:左下角方块按钮div
pageWidth:浏览器宽度
BGImage:网页body的背景图
curIndex:当前用户单击页的索引，从0开始
moveBGCount:用于动画的当前次数
**********************/

var wHScrollPage={version:1.0,parentStr:"",parent:null,pageCount:0,nr:"",page:"",pageWidth:0,BGImage:"",curIndex:0,moveBGCount:0};

wHScrollPage.addPage=function(content){
	this.pageWidth = document.documentElement.clientWidth;
	this.nr = this.nr + '<div style="float:left;width:'+this.pageWidth+'px;">' + $(content)[0].innerHTML + '</div>';
	$(content)[0].innerHTML="";
	$(content)[0].style.display="none";
	
	this.page = this.page + '<div style="cursor:pointer;width:30px;height:30px;background-color:#666;float:left;margin-right:10px;"></div>';
	this.pageCount++;
};
wHScrollPage.init = function(content){
	var w=0;
	this.parent = $(content)[0];
	this.parentStr = content;
	this.parent.style.overflow="hidden";
	this.parent.style.position="relative";
	this.parent.innerHTML='<div id="wInnerContent" style="position:absolute;width:100%"></div><div id="wPage" style="position:absolute;bottom:10px;left:10px;height:30px;"></div>';
	/*添加页的内容和页签（即page）*/
	$(content + " #wInnerContent")[0].innerHTML = $(content + " #wInnerContent")[0].innerHTML + this.nr;
	$(content + " #wPage")[0].innerHTML = $(content + " #wPage")[0].innerHTML + this.page;
	$(content + " #wInnerContent")[0].style.width =this.pageCount + "00%";
	/*----------------------------*/
	document.getElementsByTagName("body")[0].style.backgroundImage = "url("+this.BGImage+")";
	$(content).height(document.documentElement.clientHeight);
	wHScrollPage.initEvent();	
}
wHScrollPage.initEvent = function(){
	var n;
	wHScrollPage.keyDown();
	$(this.parentStr + " #wPage div").each(function(index){
		$(this).click(function(){
			if(index==0)
			{
				$(wHScrollPage.parentStr + " #wInnerContent").animate({left:"0"});
			}
			else
			{
				$(wHScrollPage.parentStr + " #wInnerContent").animate({left:"-"+index+"00%"});
			}
			if(index==0 && wHScrollPage.curIndex==0)
			{
				document.getElementsByTagName("body")[0].style.backgroundPosition = "0px 0px";
			}
			else if(index>wHScrollPage.curIndex)
			{
				
				n=index*150*-1;
				document.getElementsByTagName("body")[0].style.backgroundPosition = ""+n+"px 0px";
				
				/*wHScrollPage.Timer(index);*/
			}
		});
	});
}

wHScrollPage.Timer=function(index){
	setTimeout("wHScrollPage.moveBG("+index+")",100);
}
wHScrollPage.moveBG=function(index){
	var n;
	n=index*10*-1;
	document.getElementsByTagName("body")[0].style.backgroundPosition = ""+n+"px 0px";
	if(wHScrollPage.moveBGCount<=10)
	{	wHScrollPage.moveBGCount++;
		setTimeout("wHScrollPage.moveBG("+index+")",500);
	}
	else
	{wHScrollPage.moveBGCount=0}
}

wHScrollPage.keyDown = function(){
	if(wHScrollPage.isF)
	{
		window.onkeydown = function(e){
			e = window.event || e;
			/*alert(e.keyCode);*/
		}		
	}
	else
	{
		document.onkeydown = function(e){
			e = window.event || e;
			alert("www");
			/*alert(e.keyCode);*/
		}
	}
}

wHScrollPage.isF=function(){
	if(navigator.userAgent.indexOf("Firefox")>0)
	{
		return true;
	}
	else
	{
		return false;
	}
}